﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Model.SiteAdmin;
using Jzy.BLL.SiteAdmin;
using System.Web.UI.HtmlControls;

namespace Jzy.Web.WebSite
{
    public partial class ArticleDetail : System.Web.UI.Page
    {
        private string MenuCode
        {
            get
            {
                return Request.QueryString["MenuCode"];
            }
        }

        private string PKID
        {
            get
            {
                return Request.QueryString["ID"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ArticleBO article = new ArticleBO();
            ArticleInfo info = null;
            if (!string.IsNullOrEmpty(MenuCode))
            {
                IEnumerable<ArticleInfo> list = article.GetDisplayListByCode(int.Parse(MenuCode), 1);
                if (list.Count() > 0)
                {
                    info = list.First();
                    article.SetDelegate(info);
                }
            }
            else
            {
                info = article.GetInfo(PKID);
            }
            if (info != null)
            {
                litName.Text = info.Name;
                litInputTime.Text = info.InputTime.ToString("yyyy-MM-dd");
                litContent.Text = info.Content;

                if (info.KeyWords.Trim() != "")
                {
                    PlaceHolder metaHolder = (PlaceHolder)this.Master.Page.Form.FindControl("metaHolder");
                    metaHolder.Controls.Clear();
                    this.Title = info.KeyWords;

                    HtmlMeta meta = new HtmlMeta();
                    meta.Name = "keywords";
                    meta.Content = info.KeyWords;
                    metaHolder.Controls.Add(meta);

                    meta = new HtmlMeta();
                    meta.Name = "description";
                    meta.Content = info.Summary;
                    metaHolder.Controls.Add(meta);
                }

                lnkMenu.HRef = "ArticleList.aspx?MenuCode=" + info.MenuInfo.Code;
                lnkMenu.InnerText = info.MenuInfo.Name;

                rptPicture.DataSource = info.Pictures;
                rptPicture.DataBind();
            }
        }
    }
}
